package com.future.message.Controller;

import com.future.message.Service.DataService;
import com.future.message.Utils.ResponseResult;
import com.future.message.pojo.SecurityUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@Api(tags = "部门填写数据")
public class DataController {
    @Resource
    DataService dataService;

    @ApiOperation(value = "用户填报数据")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "indexId", value = "指标id",required = true),
                    @ApiImplicitParam(name = "content", value = "填报内容",required = true),
                    @ApiImplicitParam(name = "relevantReportId", value = "分配的填报关联id",required = true)
            }
    )
    @PostMapping("/addData")
    public ResponseResult addData(Integer userId, Integer indexId, String content, MultipartFile[] src, Integer relevantReportId) {
        return dataService.addData(userId, indexId, content, src, relevantReportId);
    }

    @ApiOperation(value = "用户修改已填报数据")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "dataId", value = "填报的数据id",required = true),
                    @ApiImplicitParam(name = "content", value = "填报内容",required = true),
            }
    )
    @PutMapping("/updateData")
    public ResponseResult updateData(Integer dataId,String content) {
        return dataService.updateData(dataId, content);
    }


    @ApiOperation(value = "用户删除自己填写过的数据")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "dataId", value = "数据id",required = true),
            }
    )
    @DeleteMapping("/deleteData")
    public ResponseResult deleteData(Integer dataId) {
        return dataService.deleteData(dataId);
    }

    @ApiOperation(value = "根据id查找")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "dataId", value = "数据id",required = true),
            }
    )
    @GetMapping("/findDataById")
    public ResponseResult findDataById(Integer dataId) {
        return dataService.findDataById(dataId);
    }

    @ApiOperation(value = "遍历该用户的填写的数据")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
            }
    )
    @GetMapping("/findDataByUserId")
    public ResponseResult findDataByUserId(Integer userId) {
        return dataService.findDataByUserId(userId);
    }

    @ApiOperation(value = "遍历填报关联下填写的数据")
    @GetMapping("/findDataByRelevantReportId")
    public ResponseResult findDataByRelevantReportId(Integer relevantReportId) {
        return dataService.findDataByRelevantReportId(relevantReportId);
    }


    @ApiOperation(value = "重新上传文件")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "dataId", value = "填报的数据id",required = true)
            }
    )
    @PutMapping("/updateSrc")
    public ResponseResult updateSrc(Integer dataId,MultipartFile[] src) {
        return dataService.updateSrc(dataId, src);
    }

}
